import axios from 'axios'

const request =  function({url, method='GET', data=[], contentType = 'json'}) {
    let baseUrl = 'http://139.196.42.209:3011/' + url;
    let header = {
        'content-type': contentType === 'json' ? 'application/json' : 'application/x-www-form-urlencoded'
    }

    return new Promise((resolve, reject)=>{
        axios({
            url:baseUrl,
            method,
            data,
            header,
        }).then(res=>{
            let {status, data} = res
            if (status === 200) {
                resolve(data)
            }else{
                console.log(status, res)
            }
        }).catch(err=>{
            console.log(err)
        })
    })
}

export default {
    request,
}